package com.二叉树.静态二叉树;

public class TreeNodeDemo {
    /**
     * 先序遍历
     * @param rootNode
     */
    public static void before(TreeNode rootNode){
        if(rootNode == null){
            return;
        }
        //根节点
        System.out.println(rootNode.getValue());
        //左节点
        before(rootNode.getLeftTreeNode());
        //右节点
        before(rootNode.getRightNode());
    }

    /**
     * 中序遍历
     * @param
     */
    public static void between(TreeNode rootNode){
        if(rootNode == null){
            return;
        }
       between(rootNode.getLeftTreeNode());
        System.out.println(rootNode.getValue());
        between(rootNode.getRightNode());
    }

    /**
     * 后序遍历
     * @param rootNode
     */
    public static  void after(TreeNode rootNode){
        if(rootNode == null){
            return;
        }

        after(rootNode.getLeftTreeNode());
        after(rootNode.getRightNode());
        System.out.println(rootNode.getValue());

    }

    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode("老子");
        TreeNode treeNode1 = new TreeNode("儿子");
        TreeNode treeNode2 = new TreeNode("女儿 ");
        TreeNode treeNode3 = new TreeNode("孙子");
        TreeNode treeNode4 = new TreeNode("孙女");
        treeNode.setLeftTreeNode(treeNode1);
        treeNode.setRightNode(treeNode2);
        treeNode1.setLeftTreeNode(treeNode3);
        treeNode2.setRightNode(treeNode4);
        System.out.println("------先序遍历----------");
        before(treeNode);
        System.out.println("==========中序遍历=======");
        between(treeNode);
        System.out.println("======后序遍历=========");
        after(treeNode);

    }
}
